New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary support #218
Binary support #218
Conversation
engine.io-protocol pull request: socketio/engine.io-protocol#15 |
@@ -60,7 +61,10 @@ httpServer.on('request', function (req, res) { | |||
<script src="/path/to/engine.io.js"></script> | |||
<script> | |||
var socket = new eio.Socket('ws://localhost/'); | |||
// by default binary type is: socket.binaryType = 'arraybuffer' | |||
socket.binaryType = 'blob'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be in its own dedicated example as to avoid confusion with the typical usecase
Thanks for the great comments. I'll make the convention changes. Also I completely agree about doing the detection for encoding binary data in the parser. There is no Blob or BlobBuilder in Node is there? It should, however, be possible to send those from a browser client (which in the current implementation is not possible). |
…upgrade packet for WebSockets
* @api public | ||
*/ | ||
|
||
XHR.prototype.supportsBinary = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not always the case, as in ActiveXObject
. Why is this always true
?
Thanks for the great comments again. I'll make the style changes. Hmm yes, that value put to the prototype is just a default value, which is set to false in handshaking if needed. I should change that to not be set in the prototype at all. |
Binary support
This pull request answers issue #182 of sending binary data over engine.io. This issue involves also engine.io-client and engine.io-protocol. The work is still a bit ongoing, but I'd like to know what you guys think. This is my first OSS pull request, so be gentle. ;)
With these changes binary data can be sent from the server to the client, and the other way around. The API for sending binary data is the same as for sending utf-8 strings, but binary types are detected. When a client on a browser calls
socket.send
for anArrayBuffer
, or anArrayBufferView
the data is sent as binary. For a node server the possibilities are the aforementioned, and alsoBuffer
. The data is then received as binary on the other end. For details on how data is received on clients, consult the engine.io-client pull request. The server always receives all binary data as aBuffer
, which is the type of the message inon('message', fn)
.Binary data can be sent over all transports. For XHR polling the default setting is using responseType of XHR2 to deliver binary data directly. The engine.io client notifies the server for the possibly missing XHR2 support, so that the server knows whether to encode binary data as strings, or send them as binary. In the case of string encoding, the binary data is encoded into a base64 string. Base64 encoding is the default option for FlashSockets and JSONP polling. WebSockets have their own support for binary data. For more information on how the encoding happens, consult the engine.io-protocol pull request.